package com.yxt.dispatch.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yxt.dispatch.entity.FormEntity;
import com.yxt.dispatch.entity.FormItemEntity;
import com.yxt.dispatch.service.FormItemService;
import com.yxt.dispatch.service.FormService;
import com.yxt.dispatch.vo.SelectedVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.yxt.common.utils.PageUtils;
import com.yxt.common.utils.R;



/**
 * 表单表 
 *
 * @author august
 * @email 379249906@qq.com
 * @date 2020-08-13 13:43:27
 */
@RestController
@RequestMapping("/form")
public class FormController {
    @Autowired
    private FormService formService;

    @Autowired
    private FormItemService formItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = formService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{formId}")
    public R info(@PathVariable("formId") Long formId){
		FormEntity form = formService.getById(formId);

        return R.ok().put("form", form);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FormEntity form){
		formService.save(form);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FormEntity form){
		formService.updateById(form);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] formIds){
		formService.removeByIds(Arrays.asList(formIds));

        return R.ok();
    }

    /**
     * 复制
     */
    @RequestMapping("/copy")
    public R copy(String source,String destination,String formName){
        return formService.copy(source,destination,formName);
    }

}
